<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">

  <xi:include href="master.html" />

<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type" py:replace="''"/>
  <title>MunkiReport</title>
</head>

<body>


<?python
    sort_flip = u'false' if reverse else u'true'
    sort_keep = u'true' if reverse else u'false'
    sort_name = u'order_by=name&reverse=' + (sort_flip if order_by == u'name' else sort_keep)
    sort_user = u'order_by=user&reverse=' + (sort_flip if order_by == u'user' else sort_keep)
    sort_addr = u'order_by=addr&reverse=' + (sort_flip if order_by == u'addr' else sort_keep)
    sort_time = u'order_by=time&reverse=' + (sort_flip if order_by == u'time' else sort_keep)
    triangle = u'\u25bc' if reverse else u'\u25b2'
    triangle_name = triangle if order_by == u'name' else u''
    triangle_user = triangle if order_by == u'user' else u''
    triangle_addr = triangle if order_by == u'addr' else u''
    triangle_time = triangle if order_by == u'time' else u''
?>


  <h1>Munki Clients (${len(clients)})</h1>
  
  <table class="clientlist">
    <thead>
      <tr>
        <th><a class="sortheader" href="?${sort_name}">Client     ${triangle_name}</a></th>
        <th><a class="sortheader" href="?${sort_user}">User       ${triangle_user}</a></th>
        <th><a class="sortheader" href="?${sort_addr}">IP         ${triangle_addr}</a></th>
        <th><a class="sortheader" href="?${sort_time}">Latest Run ${triangle_time}</a></th>
      </tr>
    </thead>
    <tbody>
      <tr py:for="client in clients">
        <?python
            url = tg.url('/view/report/%s' % client.mac)
        ?>
        <td>
          <py:choose test="client.report_plist == None">
            <py:when test="False">
              <a href="${url}">${client.name}</a>
            </py:when>
            <py:otherwise>${client.name}</py:otherwise>
          </py:choose>
        </td>
        <td py:content="client.console_user">user</td>
        <td py:content="client.remote_ip" class="ip">ip</td>
        <td>
          ${client.timestamp.strftime("%Y-%m-%d %H:%M")}
          ${client.runtype}
          ${client.runstate}
          <py:if test="client.errors">
            <span class="error">
              <a href="${url}#errors">
                ${client.errors} error${"s" if client.errors > 1 else ""}
              </a>
            </span>
          </py:if>
          <py:if test="client.warnings">
            <span class="warning">
              <a href="${url}#errors">
                ${client.warnings} warning${"s" if client.warnings > 1 else ""}
              </a>
            </span>
          </py:if>
        </td>
      </tr>
    </tbody>
  </table>
</body>
</html>
